<?php
/**
 * Created by PhpStorm.
 * User: Yangjinlei
 * Date: 2018/7/6
 * Time: 10:19
 */

namespace app\common\controller;


use app\traits\ApiResponse;
use app\traits\Auth;
use think\facade\Request;

/**
 * @property \think\Request request
 */
class BaseController
{
    use ApiResponse,Auth;
    protected $user;

    protected $exclude = [];
    /**
     * BaseController constructor.
     * @param \think\Request $request
     */
    public function __construct(\think\Request $request)
    {
//        $this->user = $this->parseToken($request->header('authorizion'),'user');
        $this->request = $request;
    }

    /**
     * @return String 获取私钥内容
     */
    function Key()
    {
        return file_get_contents(Request::rootUrl() . 'pri.key');
    }

    /**
     * @return String 获取公钥内容
     */
    function pubKey()
    {
        return file_get_contents(Request::rootUrl() . 'pub.key');
    }

    /**
     * @param array $data
     * @return array
     * @throws \Exception
     */
    public function certirs(array $data)
    {
        $tmp = [];
        $params = $this->request->param();
        foreach ($data as $value){
            if (isset($params[$value]))
//                array_push($tmp,[$value=>$params[$value]]);
                $tmp[$value] = $params[$value];
            else
                throw new \Exception($value.'不存在');
        }
        return $tmp;
    }
}